home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_540 / browser / browserii_src.lzh / Draw.c < prev    next >
C/C++ Source or Header  |  1991-07-21  |  7KB  |  236 lines

  1. /*
  2.  *    Draw.c - Copyright © 1991 by S.R. & P.C.
  3.  *
  4.  *    Created:    16 Feb 1991  12:32:43
  5.  *    Modified:    21 Jul 1991  16:46:08
  6.  *
  7.  *    Make>> make
  8.  */
  9.  
  10. #include "Global.h"
  11. #include "proto/Draw.h"
  12.  
  13.  
  14. extern struct Process *MainProcess;
  15. extern struct Screen *Screen;
  16. extern struct MinList WindowList;
  17. extern struct BrowserWindow *CurrentWin;
  18. extern struct Config Config;
  19. extern short SelectNum;
  20. extern long SelectBytes, SelectBlocks;
  21.  
  22.  
  23. void Print(struct BrowserWindow *Win, struct ScrollEntry *S, short x, short y)
  24. {
  25.     struct RastPort *rp;
  26.     ULONG enable;
  27.  
  28.     rp = Win->bw_Window->RPort;
  29.     Move(rp, x, y);
  30.     SetAPen(rp, S->se_Pen);
  31.     SetDrMd(rp, (S->se_State & STATE_SELECTED)?INVERSVID|JAM2:JAM2);
  32.     enable = AskSoftStyle(rp);
  33.     if (S->se_State & STATE_GHOSTED)
  34.         SetBPen(rp, 2);
  35.     else if (S->se_State & STATE_DELETED)
  36.         enable = SetSoftStyle(rp, FSF_ITALIC, enable);
  37.     if (S->se_FileInfo.fi_Type == DLX_UNMOUNTED)
  38.         enable = SetSoftStyle(rp, FSF_BOLD, enable);
  39.     Text(rp, S->se_Print, Win->bw_PrintLen);
  40.     SetSoftStyle(rp, FS_NORMAL, enable);
  41.     SetBPen(rp, 0);
  42. }
  43.  
  44.  
  45. void ScrollAndDraw(long firstlinenum, long firstliney, long dY, long numlines)
  46. {
  47.     struct RastPort *rp;
  48.     short i,j,n,L;
  49.  
  50.     rp = CurrentWin->bw_Window->RPort;
  51.     L = CurrentWin->bw_ScrollStruct.NumLines;
  52.     ScrollRaster(rp, 0, dY, 4, 11, CurrentWin->bw_Window->Width-17, 11+9*L);
  53.     for( i=0 ; i<numlines ; i++ ) {
  54.         for( j=0 ; j<CurrentWin->bw_NumCol ; j++ ) {
  55.             n = firstlinenum+i+j*L;
  56.             if (n > CurrentWin->bw_ShownEntries-1) break;
  57.             Print(CurrentWin, CurrentWin->bw_EntryArray[n], 4+j*CurrentWin->bw_ColWidth, 18+firstliney+9*i);
  58.         }
  59.     }
  60. }
  61.  
  62.  
  63. void RedrawEntries(struct BrowserWindow *Win)
  64. {
  65.     register struct Window *W;
  66.     register struct RastPort *rp;
  67.     short i, j, m, n, tmp;
  68.  
  69.     W = Win->bw_Window;
  70.     rp = W->RPort;
  71.     SetAPen(rp,0);
  72.     RectFill(rp, 2, 10, W->Width-17, W->Height-10);
  73.     SetAPen(rp,1);
  74.     n = Win->bw_ScrollStruct.NumLines * Win->bw_NumCol;
  75.     m = (n < Win->bw_ShownEntries - Win->bw_ScrollStruct.TopEntryNumber) ? n : Win->bw_ShownEntries - Win->bw_ScrollStruct.TopEntryNumber;
  76.     
  77.     for( i=0 ; i<Win->bw_NumCol ; i++ ) {
  78.         tmp = i * Win->bw_ScrollStruct.NumLines + Win->bw_ScrollStruct.TopEntryNumber;
  79.         for( j=0 ; j<Win->bw_ScrollStruct.NumLines && i*Win->bw_ScrollStruct.NumLines+j<m ; j++ ) {
  80.             Print(Win, Win->bw_EntryArray[tmp+j], 4+i*Win->bw_ColWidth, 18+9*j);
  81.         }
  82.     }
  83. }
  84.  
  85.  
  86. void RedrawAll(void)
  87. {
  88.     RedrawEntries(CurrentWin);
  89. }
  90.  
  91.  
  92. /* Get the coordinates of a ScrollEntry. If not currently displayed, return FALSE */
  93.  
  94. BOOL GetSePosition(struct BrowserWindow *Win, struct ScrollEntry *S, struct Point *Position)
  95. {
  96.     short top, visible, i;
  97.     
  98.     top = Win->bw_ScrollStruct.TopEntryNumber;
  99.     visible = MIN(Win->bw_ScrollStruct.NumLines * Win->bw_NumCol, Win->bw_ShownEntries);
  100.     for( i=top ; i<top+visible ; i++ ) {
  101.         if (S == Win->bw_EntryArray[i]) {
  102.             Position->X = 4 + ((i-top)/Win->bw_ScrollStruct.NumLines) * Win->bw_ColWidth;
  103.             Position->Y = 18 + ((i-top)%Win->bw_ScrollStruct.NumLines) * 9;
  104.             return TRUE;
  105.         }
  106.     }
  107.     return FALSE;
  108. }
  109.  
  110.  
  111. void RefreshBottomInfo(struct BrowserWindow *Win)
  112. {
  113.     struct Window *W;
  114.     struct RastPort *rp;
  115.     short l, cx;
  116.  
  117.     W = Win->bw_Window;
  118.     rp = W->RPort;
  119.     SetDrMd(rp, JAM2);
  120.     l = strlen(Win->bw_BottomText)-1;    /* Visible length. Ignore leading space. */
  121.     if (l<0)
  122.         return;    /* No text */
  123.     SetAPen(rp, 2);
  124.     SetBPen(rp, 1);
  125.     LockLayerInfo(&Screen->LayerInfo);    /* Prevent resizing window while printing text which may trash screen */
  126.     Move(rp, -4, W->Height-2);
  127.     Text(rp, Win->bw_BottomText, (MIN(Win->bw_BottomLen, l))+1);
  128.     SetBPen(rp, 0);
  129.     SetAPen(rp, 1);
  130.     cx = rp->cp_x;
  131.     Move(rp, cx, W->Height-9);
  132.     Draw(rp, 0, W->Height-9);
  133.     if (l < Win->bw_BottomLen)
  134.         RectFill(rp, cx, W->Height-9, W->Width-17, W->Height-1);
  135.     UnlockLayerInfo(&Screen->LayerInfo);
  136. }
  137.  
  138.  
  139. void MakeMainBottomInfoString(void)
  140. {
  141.     static struct InfoData *info = NULL;
  142.     struct BrowserWindow *Main;
  143.     long FreeBlocks, FreeBytes;
  144.     char VolumeName[34];
  145.  
  146.     if (info || (info = ArpAlloc(sizeof(struct InfoData)))) {
  147.         Main = (struct BrowserWindow *)WindowList.mlh_Head;
  148.         if (CurrentWin->bw_Type == BW_MAIN)
  149.             SPrintf(Main->bw_BottomText, " %ld Bytes  %ld Blocks  %d Entries selected",
  150.                                           SelectBytes, SelectBlocks, SelectNum);
  151.         else {
  152.             MainProcess->pr_WindowPtr = (APTR)-1L;
  153.             PathName(CurrentWin->bw_RootLock, VolumeName, 32);
  154.             if (Info(CurrentWin->bw_RootLock, info)) {
  155.                 FreeBlocks = info->id_NumBlocks - info->id_NumBlocksUsed;
  156.                 FreeBytes = FreeBlocks * info->id_BytesPerBlock;
  157.                 SPrintf(Main->bw_BottomText, " %s %ld KBytes  %ld Blocks Free", VolumeName, FreeBytes>>10, FreeBlocks);
  158.             }
  159.             else
  160.                 SPrintf(Main->bw_BottomText, " %s Volume not mounted", VolumeName);
  161.             MainProcess->pr_WindowPtr = (APTR)Main->bw_Window;
  162.         }
  163.         RefreshBottomInfo(Main);
  164.     }
  165. }
  166.  
  167.  
  168. void MakeBottomInfoString(struct BrowserWindow *Win)
  169. {
  170.     if (Win->bw_Type == BW_DIR) {
  171.         if (Win->bw_SelectNum > 0) {
  172.             SPrintf(Win->bw_BottomText, " %ld/%ld Bytes  %ld/%ld Blocks  %d/%d  Entries selected",
  173.             Win->bw_SelectBytes, Win->bw_ShownBytes,
  174.             Win->bw_SelectBlocks, Win->bw_ShownBlocks,
  175.             Win->bw_SelectNum, Win->bw_ShownEntries);
  176.         }
  177.         else {
  178.             SPrintf(Win->bw_BottomText,
  179.                     " %d/%d Files  %d/%d Dirs  %ld/%ld Bytes  %ld/%ld Blocks",
  180.                     Win->bw_ShownFiles, Win->bw_NumFiles,
  181.                     Win->bw_ShownDirs, Win->bw_NumDirs,
  182.                     Win->bw_ShownBytes, Win->bw_NumBytes,
  183.                     Win->bw_ShownBlocks, Win->bw_NumBlocks);
  184.         }
  185.     }
  186.     MakeMainBottomInfoString();
  187. }
  188.  
  189.  
  190. void RefreshWindow(struct BrowserWindow *Win)
  191. {
  192.     struct BrowserWindow *OldCurrent;
  193.     struct Window *W;
  194.     struct RastPort *rp;
  195.  
  196.     W = Win->bw_Window;
  197.     rp = W->RPort;
  198.     SetDrMd(rp, JAM2);
  199.     Win->bw_ScrollStruct.NumLines = (W->Height-21)/9;
  200.     Win->bw_ColWidth = 8 * (Win->bw_PrintStringLen+1);
  201.     Win->bw_NumCol = (W->Width-22)/Win->bw_ColWidth;
  202.     Win->bw_BottomLen = (W->Width-22)/8;
  203.     SetAPen(rp, 1);
  204.     RectFill(rp, 0, W->Height-9, W->Width-17, W->Height-1);
  205.     RefreshBottomInfo(Win);
  206.     if (Win->bw_NumCol == 0) {
  207.         Win->bw_NumCol = 1;
  208.         Win->bw_PrintLen = Win->bw_BottomLen;
  209.     }
  210.     else {
  211.         Win->bw_PrintLen = Win->bw_PrintStringLen;
  212.     }
  213.     if (Win->bw_ScrollStruct.NumLines * Win->bw_NumCol >= Win->bw_ShownEntries) {
  214.         Win->bw_ScrollStruct.NumEntries = Win->bw_ScrollStruct.NumLines;
  215.         Win->bw_ScrollStruct.TopEntryNumber = 0;
  216.     }
  217.     else {
  218.         Win->bw_ScrollStruct.NumEntries = Win->bw_ShownEntries - Win->bw_ScrollStruct.NumLines * (Win->bw_NumCol-1);
  219.     }
  220.     /* This can happen after deleting entries in window */
  221.     if (Win->bw_ScrollStruct.TopEntryNumber >= Win->bw_ShownEntries) {
  222.         Win->bw_ScrollStruct.TopEntryNumber = Win->bw_ShownEntries - Win->bw_ScrollStruct.NumLines * Win->bw_NumCol;
  223.         if (((long)Win->bw_ScrollStruct.TopEntryNumber) < 0)
  224.             Win->bw_ScrollStruct.TopEntryNumber = 0;
  225.     }
  226.     Win->bw_Prop.Info.VertBody = SetSize(Win->bw_ShownEntries, Win->bw_ScrollStruct.NumLines*Win->bw_NumCol);
  227.     RefreshGList(&Win->bw_Prop.Gadget, W, NULL, 1);
  228.     RedrawEntries(Win);
  229.     OldCurrent = CurrentWin;
  230.     CurrentWin = Win;    /* RealTimeScroll() calls functions that need CurrentWin */
  231.     RealTimeScroll(&Win->bw_ScrollStruct);
  232.     CurrentWin = OldCurrent;
  233. }
  234.  
  235.  
  236.